// consider making all what can be passed on the command line
// "arguments". Our terminology to separate them in commands and options is not
// consistent.

#ifndef LONGKEY_COMMON_COMMAND_LINE_H_
#define LONGKEY_COMMON_COMMAND_LINE_H_

#include <atlstr.h>
#include <vector>
#include "../base/constants.h"
#include "../base/browser_utils.h"

// Replacement for the C runtime function to process the command line.
// The first token of the command line in Windows is the process name.
// What gets passed to WinMain by the C runtime must not include the first
// token. Since our tiny shell does not use the C runtime we must handle
// the command line by ourselves.
TCHAR* GetCmdLindTail(const TCHAR* cmd_line);

struct CommandLineAppArgs
{
	GUID app_guid;
	CString app_name;
};

// Values may be sent in pings or stats. Do not remove or reuse existing values.
typedef enum CommandLineMode
{
	COMMANDLINE_MODE_UNKNOWN	= 0,
	COMMANDLINE_MODE_NOARGS		= 1,
	COMMANDLINE_MODE_CORE		= 2,
	COMMANDLINE_MODE_SERVICE	= 3,
	COMMANDLINE_MODE_REGSERVER	= 4,
	COMMANDLINE_MODE_UNREGSERVER= 5,
	COMMANDLINE_MODE_NETDIAGS	= 6,
	COMMANDLINE_MODE_CRASH		= 7,
	COMMANDLINE_MODE_REPORTCRASH= 8,
	COMMANDLINE_MODE_INSTALL	= 9,
	COMMANDLINE_MODE_UPDATE		= 10,
	COMMANDLINE_MODE_COMSERVER	= 18,

	COMMANDLINE_MODE_SERVICE_REGISTER	= 23,
	COMMANDLINE_MODE_SERVICE_UNREGISTER	= 24,
};

struct CommandLineExtraArgs {
	CommandLineExtraArgs()
		: installation_id(GUID_NULL),
		browser_type(BROWSER_UNKNOWN),
		usage_stats_enable(TRISTATE_NONE),
		runtime_only(false) {}

	CString bundle_name;
	GUID installation_id;
	CString brand_code;
	CString client_id;
	CString experiment_labels;
	CString referral_id;
	CString language;
	BrowserType browser_type;
	Tristate usage_stats_enable;
	bool runtime_only;

	std::vector<CommandLineAppArgs> apps;
};

struct CommandLineArgs {
	CommandLineArgs()
		: mode(COMMANDLINE_MODE_UNKNOWN),
		is_interactive_set(false),
		is_machine_set(false),
		is_crash_handler_disabled(false),
		is_install_elevated(false),
		is_silent_set(false),
		is_eula_required_set(false),
		is_offline_set(false),
		is_oem_set(false) {}

	CommandLineMode mode;
	bool is_interactive_set;
	bool is_machine_set;
	bool is_crash_handler_disabled;
	bool is_install_elevated;
	bool is_silent_set;
	bool is_eula_required_set;
	bool is_offline_set;
	bool is_oem_set;
	CString extra_args_str;
	CString app_args_str;
	CString install_source;
	CString crash_filename;
	CString custom_info_filename;
	CString legacy_manifest_path;
	CString webplugin_urldomain;
	CString webplugin_args;
	CString code_red_metainstaller_path;
	CString ping_string;
	CString offline_dir;
	CString session_id;
	CommandLineExtraArgs extra;
};

// Parses the pcagent command line.
HRESULT ParseCommandLine(const TCHAR* cmd_line, CommandLineArgs* args);

#endif	// LONGKEY_COMMON_COMMAND_LINE_H_